package mi.payment.ui.other;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import mi.payment.R;
import mi.payment.constants.Params;
import mi.payment.db.dao.PayDetail;
import mi.payment.transaction.AutoFinishActivity;
import sunmi.payment.L3.L3BroadcastHelper;
import sunmi.payment.L3.L3ErrorCode;

/**
 * 交易失败，当需要进行冲正时，弹出此界面提示收银员需要冲正
 */
public class CorrectResultActivity extends AutoFinishActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_correct_result);
        initView();
    }

    private void initView() {
        final PayDetail payDetail = (PayDetail) getIntent().getSerializableExtra("payDetail");

        RelativeLayout rlLogin = (RelativeLayout) findViewById(R.id.login_out);
        rlLogin.setVisibility(View.GONE);

        TextView tvTitle = (TextView) findViewById(R.id.home_page_title_text);
        tvTitle.setText(R.string.transaction_result);

        ImageView ivResult = (ImageView) findViewById(R.id.iv_correct_result);
        ivResult.setImageDrawable(getResources().getDrawable(R.drawable.state_correct_result_fail));

        RelativeLayout layoutBack = (RelativeLayout) findViewById(R.id.rl_back);
        layoutBack.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (Params.sL3Params != null) {
                    L3BroadcastHelper.sendResultBroadcast(CorrectResultActivity.this, false, L3ErrorCode.ERROR_TRADE_FAILED, payDetail);
                }
                sendCloseActivityBroadcast();
                finish();
            }

        });
    }

    public static void startAction(Context context, PayDetail payDetail) {
        Intent intent = new Intent(context, CorrectResultActivity.class);
        intent.putExtra("payDetail", payDetail);
        context.startActivity(intent);
    }


}